package com.itheima.employee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.employee.mapper.TransferPositionMapper;
import com.itheima.employee.pojo.EmployeeTransferPosition;
import com.itheima.employee.service.TransferPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * @author qiankaofei
 * @version 1.0
 * @date 2020/11/16 10:45
 */
@Service
@Transactional
public class TransferPositionServiceImpl implements TransferPositionService {

    private static final Integer NOESTATUS=1;

    @Autowired
    private TransferPositionMapper transferPositionMapper;

    public EmployeeTransferPosition findById(String uid, Integer status) {
        QueryWrapper<EmployeeTransferPosition> wrapper=new QueryWrapper<EmployeeTransferPosition>();
        EmployeeTransferPosition transferPosition = transferPositionMapper.selectOne(wrapper.eq("user_id", uid));
        if(status!=null && transferPosition!=null){
            if(transferPosition.getEstatus() != status){
                transferPosition=null;
            }
        }
        return transferPosition;
    }

    /**
     * 调岗表单保存
     */
    public Integer save(EmployeeTransferPosition transferPosition) {
        transferPosition.setCreateTime(new Date());
        transferPosition.setEstatus(NOESTATUS);
        return transferPositionMapper.insert(transferPosition);
    }
}
